<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 7.3.0">

  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.ico">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" integrity="sha256-wiz7ZSCn/btzhjKDQBms9Hx4sSeUYsDrTLg7roPstac=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.css" integrity="sha256-6cQIC71/iBIYXFK+0RHAvwmjwWzkWd+r7v/BX3/vZDc=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/themes/green/pace-theme-minimal.css">
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.2.4/pace.min.js" integrity="sha256-gqd7YTjg/BtfqWSwsJOvndl0Bxc8gFImLEkXQT8+qj0=" crossorigin="anonymous"></script>

<script class="next-config" data-name="main" type="application/json">{"hostname":"sumumm.github.io","root":"/","images":"/images","scheme":"Gemini","darkmode":false,"version":"8.19.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":{"enable":true,"style":"mac"},"fold":{"enable":true,"height":300},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":true,"transition":{"menu_item":"fadeInDown","post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}}</script><script src="/js/config.js"></script>

    <meta name="description" content="本文主要使用汇编点亮ALPHA上的LED的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:type" content="article">
<meta property="og:title" content="LV04-02-GPIO-02-汇编点亮LED灯">
<meta property="og:url" content="https://sumumm.github.io/post/35c09a55.html">
<meta property="og:site_name" content="苏木">
<meta property="og:description" content="本文主要使用汇编点亮ALPHA上的LED的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716170503614.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107075112786.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716170859666.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107223517117.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107224548462.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107225623369.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107230253702.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107230626210.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107231927152.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107232408795.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107232442328.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233451803.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233612900.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233733355.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234119303.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234356064.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234545683.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234838793.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107235412338.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234545683.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000415390.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716190816114.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000446239.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000520398.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000549113.png">
<meta property="og:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000654980.png">
<meta property="article:published_time" content="2024-11-08T12:59:32.000Z">
<meta property="article:modified_time" content="2025-06-13T16:25:57.038Z">
<meta property="article:author" content="苏木">
<meta property="article:tag" content="(ALPHA)LV04-裸机开发">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716170503614.png">


<link rel="canonical" href="https://sumumm.github.io/post/35c09a55.html">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-CN","comments":"","permalink":"https://sumumm.github.io/post/35c09a55.html","path":"post/35c09a55.html","title":"LV04-02-GPIO-02-汇编点亮LED灯"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>LV04-02-GPIO-02-汇编点亮LED灯 | 苏木</title>
  








    <script src="/js/browser_tools_disable.js"></script>

  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
<!-- hexo injector head_end start --><link rel="stylesheet" href="https://unpkg.com/hexo-next-tags-plus@latest/lib/tag_plus.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --></head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <div class="column">
      <header class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">苏木</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">我的学习之路</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger" aria-label="搜索" role="button">
        <i class="fa fa-search fa-fw fa-lg"></i>
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>苏木的家</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类页<span class="badge">42</span></a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档页<span class="badge">673</span></a></li><li class="menu-item menu-item-flink"><a href="/flink/" rel="section"><i class="fa fa-link fa-fw"></i>友人帐</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="fa fa-user fa-fw"></i>关于我</a></li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>
</nav>



  <div class="search-pop-overlay">
    <div class="popup search-popup"><div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocapitalize="off" maxlength="80"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close" role="button">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div class="search-result-container no-result">
  <div class="search-result-icon">
    <i class="fa fa-spinner fa-pulse fa-5x"></i>
  </div>
</div>

    </div>
  </div>

</header>
        
  
  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%80%E3%80%81%E7%A1%AC%E4%BB%B6%E5%8E%9F%E7%90%86%E5%9B%BE"><span class="nav-text">一、硬件原理图</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%8C%E3%80%81%E6%80%8E%E4%B9%88%E6%93%8D%E4%BD%9CGPIO%EF%BC%9F"><span class="nav-text">二、怎么操作GPIO？</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-%E5%9F%BA%E6%9C%AC%E6%AD%A5%E9%AA%A4"><span class="nav-text">1. 基本步骤</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-GPIO%E5%AF%84%E5%AD%98%E5%99%A8%E6%93%8D%E4%BD%9C"><span class="nav-text">2. GPIO寄存器操作</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%B8%89%E3%80%81%E4%BB%A3%E7%A0%81%E7%BC%96%E5%86%99%E4%B8%8E%E5%88%86%E6%9E%90"><span class="nav-text">三、代码编写与分析</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-led-s%E5%AE%8C%E6%95%B4%E5%86%85%E5%AE%B9"><span class="nav-text">1. led.s完整内容</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-%E8%AF%A6%E7%BB%86%E5%88%86%E6%9E%90"><span class="nav-text">2. 详细分析</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#2-1-%E5%85%A8%E5%B1%80%E6%A0%87%E5%8F%B7"><span class="nav-text">2.1 全局标号</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-2-%E4%BD%BF%E8%83%BD%E6%97%B6%E9%92%9F"><span class="nav-text">2.2 使能时钟</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-1-GPIO%E6%97%B6%E9%92%9F%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2.2.1 GPIO时钟用哪个寄存器？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-2-%E5%AF%84%E5%AD%98%E5%99%A8%E5%9C%B0%E5%9D%80%EF%BC%9F"><span class="nav-text">2.2.2 寄存器地址？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-2-3-%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-text">2.2.3 代码分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-3-%E8%AE%BE%E7%BD%AEIO%E5%A4%8D%E7%94%A8%E5%8A%9F%E8%83%BD"><span class="nav-text">2.3 设置IO复用功能</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-1-%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2.3.1 用哪个寄存器？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-2-%E5%AF%84%E5%AD%98%E5%99%A8%E5%9C%B0%E5%9D%80%EF%BC%9F"><span class="nav-text">2.3.2 寄存器地址？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-3-3-%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-text">2.3.3 代码分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-4-%E8%AE%BE%E7%BD%AEIO%E5%B1%9E%E6%80%A7"><span class="nav-text">2.4 设置IO属性</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-1-%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2.4.1 用哪个寄存器？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-2-%E5%AF%84%E5%AD%98%E5%99%A8%E5%9C%B0%E5%9D%80%EF%BC%9F"><span class="nav-text">2.4.2 寄存器地址？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-4-3-%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-text">2.4.3 代码分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-5-%E8%AE%BE%E7%BD%AEGPIO%E5%8A%9F%E8%83%BD"><span class="nav-text">2.5 设置GPIO功能</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-5-1-%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2.5.1 用哪个寄存器？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-5-2-%E5%AF%84%E5%AD%98%E5%99%A8%E5%9C%B0%E5%9D%80%EF%BC%9F"><span class="nav-text">2.5.2 寄存器地址？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-5-3-%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-text">2.5.3 代码分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-6-%E8%AE%BE%E7%BD%AEGPIO%E8%BE%93%E5%87%BA%E7%94%B5%E5%B9%B3"><span class="nav-text">2.6 设置GPIO输出电平</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#2-6-1-%E7%94%A8%E5%93%AA%E4%B8%AA%E5%AF%84%E5%AD%98%E5%99%A8%EF%BC%9F"><span class="nav-text">2.6.1 用哪个寄存器？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-6-2-%E5%AF%84%E5%AD%98%E5%99%A8%E5%9C%B0%E5%9D%80%EF%BC%9F"><span class="nav-text">2.6.2 寄存器地址？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#2-6-3-%E4%BB%A3%E7%A0%81%E5%88%86%E6%9E%90"><span class="nav-text">2.6.3 代码分析</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-7-%E6%AD%BB%E5%BE%AA%E7%8E%AF"><span class="nav-text">2.7 死循环</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E5%9B%9B%E3%80%81%E7%BC%96%E8%AF%91%E7%A8%8B%E5%BA%8F"><span class="nav-text">四、编译程序</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#1-arm-linux-gnueabihf-gcc-%E7%BC%96%E8%AF%91%E6%96%87%E4%BB%B6"><span class="nav-text">1. arm-linux-gnueabihf-gcc 编译文件  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#2-arm-linux-gnueabihf-ld-%E9%93%BE%E6%8E%A5%E6%96%87%E4%BB%B6"><span class="nav-text">2. arm-linux-gnueabihf-ld 链接文件  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#3-arm-linux-gnueabihf-objcopy-%E6%A0%BC%E5%BC%8F%E8%BD%AC%E6%8D%A2"><span class="nav-text">3. arm-linux-gnueabihf-objcopy 格式转换  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#4-arm-linux-gnueabihf-objdump-%E5%8F%8D%E6%B1%87%E7%BC%96"><span class="nav-text">4. arm-linux-gnueabihf-objdump 反汇编  </span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#5-%E5%88%9B%E5%BB%BA-Makefile-%E6%96%87%E4%BB%B6"><span class="nav-text">5. 创建 Makefile 文件  </span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E4%BA%94%E3%80%81%E7%A8%8B%E5%BA%8F%E7%83%A7%E5%86%99"><span class="nav-text">五、程序烧写</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="苏木"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">苏木</p>
  <div class="site-description" itemprop="description">莫道桑榆晚，为霞尚满天</div>
</div>
<div class="site-state-wrap animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">673</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">42</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
        <span class="site-state-item-count">43</span>
        <span class="site-state-item-name">标签</span>
      </div>
  </nav>
</div>
  <div class="links-of-author animated">
      <span class="links-of-author-item">
        <a href="https://github.com/sumumm" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;sumumm" rel="noopener me" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
  </div>

        </div>
      </div>
    </div>

    
  </aside>


    </div>

    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://sumumm.github.io/post/35c09a55.html">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="苏木">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏木">
      <meta itemprop="description" content="莫道桑榆晚，为霞尚满天">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="LV04-02-GPIO-02-汇编点亮LED灯 | 苏木">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          LV04-02-GPIO-02-汇编点亮LED灯
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2024-11-08 20:59:32" itemprop="dateCreated datePublished" datetime="2024-11-08T20:59:32+08:00">2024-11-08</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">嵌入式开发</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/" itemprop="url" rel="index"><span itemprop="name">02IMX6ULL平台</span></a>
        </span>
          ，
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" itemprop="url" rel="index"><span itemprop="name">LV04-裸机开发</span></a>
        </span>
    </span>

  
    <span class="post-meta-break"></span>
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>7.3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>26 分钟</span>
    </span>
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody"><p>本文主要使用汇编点亮ALPHA上的LED的相关笔记，若笔记中有错误或者不合适的地方，欢迎批评指正😃。</p>
<span id="more"></span>

<!-- Photo: https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/ -->

<details class="folding-tag" blue><summary> 点击查看使用工具及版本 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center" width=150px>Windows版本</td>        <td align="left">windows11</td>    </tr>    <tr>        <td align="center">Ubuntu版本</td>        <td align="left">Ubuntu16.04的64位版本</td>      </tr>    <tr>        <td align="center">VMware® Workstation 16 Pro</td>        <td align="left">16.2.3 build-19376536</td>      </tr>    <tr>        <td align="center">终端软件</td>        <td align="left">MobaXterm(Professional Edition v23.0 Build 5042 (license))</td>      </tr>    <tr>        <td align="center">Linux开发板</td>        <td align="left">正点原子 i.MX6ULL Linux 阿尔法开发板</td>      </tr>    <tr>        <td align="center">uboot</td>        <td align="left">NXP官方提供的uboot，NXP提供的版本为uboot-imx-rel_imx_4.1.15_2.1.0_ga(使用的uboot版本为U-Boot 2016.03)</td>      </tr>    <tr>        <td align="center">linux内核</td>        <td align="left">linux-4.15(NXP官方提供)</td>      </tr>    <tr>        <td align="center">Win32DiskImager</td>        <td align="left">Win32DiskImager v1.0</td>      </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看本文参考资料 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="5">官方网站</td>        <td align="left"><a href="https://www.arm.com/" target="_blank">https://www.arm.com/</a></td>        <td align="left">ARM官方网站，在这里我们可以找到Cotex-Mx以及ARMVx的一些文档</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/" target="_blank">https://www.nxp.com.cn/ </a></td>        <td align="left">NXP官方网站</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxpic.org.cn/" target="_blank">https://www.nxpic.org.cn/</a></td><td align="left">NXP 官方社区</td>    </tr>    <tr>        <td align="left"><a href="https://u-boot.readthedocs.io/en/latest/" target="_blank">https://u-boot.readthedocs.io/en/latest/</a></td><td align="left">u-boot官网</td>    </tr>    <tr>        <td align="left"><a href="https://www.kernel.org/" target="_blank">https://www.kernel.org/</a></td><td align="left">linux内核官网</td>    </tr></table>
              </div>
            </details>

<details class="folding-tag" blue><summary> 点击查看相关文件下载 </summary>
              <div class='content'>
              <table>    <tr>        <td align="center">分类</td>        <td align="center">网址</td>        <td align="center">说明</td>    </tr>    <tr>        <td align="center" rowspan="4">NXP</td>        <td align="left"><a href="https://github.com/nxp-imx" target="_blank">https://github.com/nxp-imx</a></td>        <td align="left">NXP imx开发资源GitHub组织，里边会有u-boot和linux内核的仓库</td>    </tr>    <tr>        <td align="left"><a href="https://elixir.bootlin.com/linux/latest/source" target="_blank">https://elixir.bootlin.com/linux/latest/source</a></td>        <td align="left">在线阅读linux kernel源码</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/linux-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP linux内核仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="left"><a href="https://github.com/nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga" target="_blank">nxp-imx/uboot-imx/releases/tag/rel_imx_4.1.15_2.1.0_ga</a></td>        <td align="left">NXP u-boot仓库tags中的rel_imx_4.1.15_2.1.0_ga</td>    </tr>    <tr>        <td align="center" rowspan="2">I.MX6ULL</td>        <td align="left"><a href="https://www.nxp.com.cn/docs/en/data-sheet/IMX6ULLIEC.pdf" target="_blank">i.MX 6ULL Applications Processors for Industrial Products</a></td>        <td align="left">I.MX6ULL 芯片手册（datasheet，可以在线查看）</td>    </tr>    <tr>        <td align="left"><a href="https://www.nxp.com.cn/webapp/Download?colCode=IMX6ULLRM&lang_cd=zh" target="_blank">i.MX 6ULL Applications ProcessorReference Manual</a></td>        <td align="left">I.MX6ULL 参考手册（下载后才能查看，需要登录NXP官网）</td>    </tr></table>
              </div>
            </details>

<h1 id="一、硬件原理图"><a href="#一、硬件原理图" class="headerlink" title="一、硬件原理图"></a><font size=3>一、硬件原理图</font></h1><p>我们先看底板原理图（”阿尔法Linux开发板（A盘）-基础资料&#x2F;02、开发板原理图&#x2F;IMX6ULL_ALPHA_V2.2(底板原理图).pdf”</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716170503614.png" alt="image-20230716170503614" style="zoom:50%;" />



<p>可以看到LED0 接到了 GPIO_3 上， 这个GPIO_3是哪个引脚？感觉这里标的有问题，我们搜索一下，会发现这里接在一个BTB连接器母座上，所以我们再去搜一些核心板原理图 “阿尔法Linux开发板（A盘）-基础资料&#x2F;02、开发板原理图&#x2F;IMX6ULL_CORE_V1.6(核心板原理图).pdf”：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107075112786.png" alt="image-20241107075112786" />

<p>就会发现GPIO_3 就是 GPIO1_IO03，根据底板原理图，当 GPIO1_IO03输出低电平(0)的时候发光二极管 LED0 就会导通点亮，GPIO1_IO03 输出高电平(1)的时候发光二极管 LED0 不会导通，因此 LED0 也就不会点亮。所以 LED0 的亮灭取决于 GPIO1_IO03的输出电平，输出 0 就亮，输出 1 就灭。  </p>
<h1 id="二、怎么操作GPIO？"><a href="#二、怎么操作GPIO？" class="headerlink" title="二、怎么操作GPIO？"></a><font size=3>二、怎么操作GPIO？</font></h1><p>主要是配置三大控制模块：</p>
<figure class="highlight txt"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">CCM    : Clock Controller Module      时钟控制模块</span><br><span class="line">IOMUXC : IOMUX Controller             IO 复用控制器</span><br><span class="line">GPIO   : General-purpose input/output 通用的输入输出口</span><br></pre></td></tr></table></figure>

<h2 id="1-基本步骤"><a href="#1-基本步骤" class="headerlink" title="1. 基本步骤"></a><font size=3>1. 基本步骤</font></h2><ul>
<li>（1）使能 GPIO1 时钟</li>
</ul>
<p>GPIO1 的时钟由 CCM_CCGR1 的 bit27 和 bit26 这两个位控制，将这两个位都设置位 11 即可。</p>
<ul>
<li>（2）设置 GPIO1_IO03 的复用功能</li>
</ul>
<p>找到 GPIO1_IO03 的复用寄存器“IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03”的地址为0X020E0068，然后设置此寄存器，将 GPIO1_IO03 这个 IO 复用为 GPIO 功能，也就是 ALT5。</p>
<ul>
<li>（3）配置 GPIO1_IO03功能和参数</li>
</ul>
<p>找到 GPIO1_IO03 的配置寄存器“IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO03”的地址为0X020E02F4，根据实际使用情况，配置此寄存器。  </p>
<ul>
<li>（4）设置GPIO</li>
</ul>
<p>将 GPIO1_IO03 复用为了 GPIO 功能，我们还需要配置 GPIO。 找到 GPIO3 对应的 GPIO 组寄存器地址，在《i.MX 6ULL Applications Processor Reference Manual》的 28.5 GPIO Memory Map&#x2F;Register Definition  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716170859666.png" alt="image-20230716170859666" style="zoom:50%;" />

<p>GPIO1_IO03 是作为输出功能的，因此 GPIO1_GDIR 的 bit3 要设置为 1，表示输出。  </p>
<ul>
<li>（5）控制 GPIO 的输出电平</li>
</ul>
<p>向 GPIO1_DR 寄存器的 bit3 写入 0 即可控制 GPIO1_IO03 输出低电平，打开 LED，向 bit3 写入 1 可控制 GPIO1_IO03 输出高电平，关闭 LED。</p>
<h2 id="2-GPIO寄存器操作"><a href="#2-GPIO寄存器操作" class="headerlink" title="2. GPIO寄存器操作"></a><font size=3>2. GPIO寄存器操作</font></h2><p>GPIO 寄存器的 2 种操作方法，原则是不能影响到其他位 。</p>
<p>（1）读出、修改对应位、写入  </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">/* 设置bit n */</span><br><span class="line">val = data_reg;</span><br><span class="line">val = val | (1 &lt;&lt; n);</span><br><span class="line">data_reg = val;</span><br><span class="line"></span><br><span class="line">/* 清除 bit n */</span><br><span class="line">val = data_reg;</span><br><span class="line">val = val &amp; ~(1 &lt;&lt; n);</span><br><span class="line">data_reg = val;</span><br></pre></td></tr></table></figure>

<p>（2）set-and-clear protocol</p>
<p>set_reg, clr_reg, data_reg 三个寄存器对应的是同一个物理寄存器,  </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">/* 要设置 bit n */</span><br><span class="line">set_reg = (1&lt;&lt;n);</span><br><span class="line">/* 要清除 bit n */</span><br><span class="line">clr_reg = (1&lt;&lt;n);</span><br></pre></td></tr></table></figure>

<p>这种方式会影响到其他的位，还是上面的方式更好一些，只针对某一位进行操作。</p>
<h1 id="三、代码编写与分析"><a href="#三、代码编写与分析" class="headerlink" title="三、代码编写与分析"></a><font size=3>三、代码编写与分析</font></h1><h2 id="1-led-s完整内容"><a href="#1-led-s完整内容" class="headerlink" title="1. led.s完整内容"></a><font size=3>1. led.s完整内容</font></h2><details class="folding-tag" blue><summary> 点击查看 led.s 文件内容 </summary>
              <div class='content'>
              <figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br></pre></td><td class="code"><pre><span class="line">.global _start  /* 全局标号 */</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 描述：	_start函数，程序从此函数开始执行此函数完成时钟使能、</span><br><span class="line"> *		  GPIO初始化、最终控制GPIO输出低电平来点亮LED灯。</span><br><span class="line"> */</span><br><span class="line">_start:</span><br><span class="line">	/* 例程代码 */</span><br><span class="line">	/* 1、使能所有时钟 */</span><br><span class="line">	ldr r0, =0X020C4068 	/* CCGR0 */</span><br><span class="line">	ldr r1, =0XFFFFFFFF  </span><br><span class="line">	str r1, [r0]		</span><br><span class="line">	</span><br><span class="line">	ldr r0, =0X020C406C  	/* CCGR1 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line"></span><br><span class="line">	ldr r0, =0X020C4070  	/* CCGR2 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line">	</span><br><span class="line">	ldr r0, =0X020C4074  	/* CCGR3 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line">	</span><br><span class="line">	ldr r0, =0X020C4078  	/* CCGR4 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line">	</span><br><span class="line">	ldr r0, =0X020C407C  	/* CCGR5 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line">	</span><br><span class="line">	ldr r0, =0X020C4080  	/* CCGR6 */</span><br><span class="line">	str r1, [r0]</span><br><span class="line">	</span><br><span class="line"></span><br><span class="line">	/* 2、设置GPIO1_IO03复用为GPIO1_IO03 */</span><br><span class="line">	ldr r0, =0X020E0068	/* 将寄存器SW_MUX_GPIO1_IO03_BASE加载到r0中 */</span><br><span class="line">	ldr r1, =0X5		/* 设置寄存器SW_MUX_GPIO1_IO03_BASE的MUX_MODE为5 */</span><br><span class="line">	str r1,[r0]</span><br><span class="line"></span><br><span class="line">	/* 3、配置GPIO1_IO03的IO属性	</span><br><span class="line">	 * bit 16:0 HYS关闭</span><br><span class="line">	 * bit [15:14]: 00 默认下拉</span><br><span class="line">     * bit [13]: 0 kepper功能</span><br><span class="line">     * bit [12]: 1 pull/keeper使能</span><br><span class="line">     * bit [11]: 0 关闭开路输出</span><br><span class="line">     * bit [7:6]: 10 速度100Mhz</span><br><span class="line">     * bit [5:3]: 110 R0/6驱动能力</span><br><span class="line">     * bit [0]: 0 低转换率</span><br><span class="line">     */</span><br><span class="line">    ldr r0, =0X020E02F4	/*寄存器SW_PAD_GPIO1_IO03_BASE */</span><br><span class="line">    ldr r1, =0X10B0</span><br><span class="line">    str r1,[r0]</span><br><span class="line"></span><br><span class="line">	/* 4、设置GPIO1_IO03为输出 */</span><br><span class="line">    ldr r0, =0X0209C004	/*寄存器GPIO1_GDIR */</span><br><span class="line">    ldr r1, =0X0000008		</span><br><span class="line">    str r1,[r0]</span><br><span class="line"></span><br><span class="line">	/* 5、打开LED0</span><br><span class="line">	 * 设置GPIO1_IO03输出低电平</span><br><span class="line">	 */</span><br><span class="line">    ldr r0, =0X0209C000	/*寄存器GPIO1_DR */</span><br><span class="line">    ldr r1, =0		</span><br><span class="line">    str r1,[r0]</span><br><span class="line"></span><br><span class="line">/*</span><br><span class="line"> * 描述：	loop死循环</span><br><span class="line"> */</span><br><span class="line">loop:</span><br><span class="line">	b loop 				</span><br></pre></td></tr></table></figure>
              </div>
            </details>

<h2 id="2-详细分析"><a href="#2-详细分析" class="headerlink" title="2. 详细分析"></a><font size=3>2. 详细分析</font></h2><h3 id="2-1-全局标号"><a href="#2-1-全局标号" class="headerlink" title="2.1 全局标号"></a><font size=3>2.1 全局标号</font></h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">.global _start  /* 全局标号 */</span><br></pre></td></tr></table></figure>

<p>定义了一个全局标号_start，代码就是从_start 这个标号开始顺序往下执行的。  </p>
<h3 id="2-2-使能时钟"><a href="#2-2-使能时钟" class="headerlink" title="2.2 使能时钟"></a><font size=3>2.2 使能时钟</font></h3><h4 id="2-2-1-GPIO时钟用哪个寄存器？"><a href="#2-2-1-GPIO时钟用哪个寄存器？" class="headerlink" title="2.2.1 GPIO时钟用哪个寄存器？"></a><font size=3>2.2.1 GPIO时钟用哪个寄存器？</font></h4><p>我们翻一下《i.MX 6ULL Applications Processor Reference Manual》18.4 System Clocks  这一节，我们看一下Table 18-3. System Clocks, Gating, and Override (continued)  这个表格，具体GPIO应该是在 P635：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107223517117.png" alt="image-20241107223517117" style="zoom: 50%;" />

<p>可以看到这里每一组的GPIO时钟是由CCM_CCGRx寄存器来控制，我们使用的是GPIO1所以对应的应该是CCM_CCGR1[CG13]，我们看一下这个是什么，我们可以全局搜索CCGR1，就可以找到这个寄存器，它其实位于参考手册18.6.24 CCM Clock Gating Register 1 (CCM_CCGR1)这一节，大概在P 700：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107224548462.png" alt="image-20241107224548462" style="zoom:50%;" />

<p>可以看到，这个是个32位寄存器，每两位控制一个时钟，我们的GPIO1就位于27-26，就是CG13，可以看到这个前面的表格是对应的，那么这两位怎么配置表示开启时钟？我们可以再在18.6.23 CCM Clock Gating Register 0 (CCM_CCGR0)  这一节找到：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107225623369.png" alt="image-20241107225623369" style="zoom:50%;" />

<table>
<thead>
<tr>
<th>CGR</th>
<th>时钟状态描述</th>
</tr>
</thead>
<tbody><tr>
<td>00</td>
<td>时钟在所有模式下都是关闭的</td>
</tr>
<tr>
<td>01</td>
<td>时钟在运行模式下为开，但在等待和停止模式下为关</td>
</tr>
<tr>
<td>10</td>
<td>保留</td>
</tr>
<tr>
<td>11</td>
<td>除停止模式外，时钟一直开启</td>
</tr>
</tbody></table>
<p>目前我们可以全部设置为1，我们看上面的寄存器描述中，有一个reset，这个表示默认状态下的复位后的值，发现它其实默认就是11，也就是说时钟默认是打开的，但是为了规范，我们还是需要操作一遍。</p>
<h4 id="2-2-2-寄存器地址？"><a href="#2-2-2-寄存器地址？" class="headerlink" title="2.2.2 寄存器地址？"></a><font size=3>2.2.2 寄存器地址？</font></h4><p>我们知道要用到哪个寄存器，并且也知道了要配什么值，那么怎么操作？我们需要找到这个寄存器的地址，然后写值进去，地址怎么找？其实刚才找寄存器的时候有的：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107230253702.png" alt="image-20241107230253702" style="zoom:50%;" />

<p>这里就写了，基地址是20C_4000h，偏移地址是6Ch，加到一起就是绝对地址 20C_406Ch。其实参考手册还有一个地方可以看到，就是这里：18.6 CCM Memory Map&#x2F;Register Definition  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107230626210.png" alt="image-20241107230626210" style="zoom:50%;" />

<p>从这里可以直接看到寄存器的绝对地址和默认值。</p>
<h4 id="2-2-3-代码分析"><a href="#2-2-3-代码分析" class="headerlink" title="2.2.3 代码分析"></a><font size=3>2.2.3 代码分析</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">ldr r0, =0X020C4068 	/* CCGR0 */</span><br><span class="line">ldr r1, =0XFFFFFFFF  </span><br><span class="line">str r1, [r0]		</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C406C  	/* CCGR1 */</span><br><span class="line">str r1, [r0]</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C4070  	/* CCGR2 */</span><br><span class="line">str r1, [r0]</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C4074  	/* CCGR3 */</span><br><span class="line">str r1, [r0]</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C4078  	/* CCGR4 */</span><br><span class="line">str r1, [r0]</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C407C  	/* CCGR5 */</span><br><span class="line">str r1, [r0]</span><br><span class="line"></span><br><span class="line">ldr r0, =0X020C4080  	/* CCGR6 */</span><br><span class="line">str r1, [r0]</span><br></pre></td></tr></table></figure>

<p>第 1 行：使用 ldr 指令向寄存器 r0 写入 0X020C4068，也就是 r0&#x3D;0X020C4068，这个是CCM_CCGR0 寄存器的地址。</p>
<p>第 2 行：使用 ldr 指令向寄存器 r1 写入 0XFFFFFFFF，也就是 r1&#x3D;0XFFFFFFFF。因为我们:要开启所有的外设时钟，因此 CCM_CCGR0 ~ CCM_CCGR6 所有寄存器的 32 位都要置 1，也就是写入 0XFFFFFFFF。</p>
<p>第 3 行：使用 str 将 r1 中的值写入到 r0 所保存的地址中去，也就是给 0X020C4068 这个地址写入 0XFFFFFFFF，相当于CCM_CCGR0 &#x3D; 0XFFFFFFFF，就是打开 CCM_CCGR0 寄存器所控制的所有外设时钟。</p>
<p>第 5 ~21 行都是向 CCM_CCGRX(X&#x3D;1~6)寄存器写入 0XFFFFFFFF。这样我就通过汇编代码使能了 I.MX6U 的所有外设时钟。  </p>
<h3 id="2-3-设置IO复用功能"><a href="#2-3-设置IO复用功能" class="headerlink" title="2.3 设置IO复用功能"></a><font size=3>2.3 设置IO复用功能</font></h3><h4 id="2-3-1-用哪个寄存器？"><a href="#2-3-1-用哪个寄存器？" class="headerlink" title="2.3.1 用哪个寄存器？"></a><font size=3>2.3.1 用哪个寄存器？</font></h4><p>前面我们知道IO有多种复用功能，这里我们需要将此引脚作为输出功能，就是普通的GPIO，用哪个寄存器？我们前面有说过，设置复用模式我们要找包含MUX_CTL关键词的配置寄存器，我们直接搜GPIO1_IO03，可以找到参考手册中这个32.6.10 SW_MUX_CTL_PAD_GPIO1_IO03 SW MUX Control Register (IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03)  这一节的这个寄存器：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107231927152.png" alt="image-20241107231927152" style="zoom:50%;" />

<p>可以看到我们需要配置这个寄存器的[3:0]为0101，这个时候这个引脚就是GPIO1_IO03功能。</p>
<h4 id="2-3-2-寄存器地址？"><a href="#2-3-2-寄存器地址？" class="headerlink" title="2.3.2 寄存器地址？"></a><font size=3>2.3.2 寄存器地址？</font></h4><p>（1）参考手册32.6.10 SW_MUX_CTL_PAD_GPIO1_IO03 SW MUX ControlRegister (IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03)  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107232408795.png" alt="image-20241107232408795" style="zoom:50%;" />

<p>（2）参考手册32.6 IOMUXC Memory Map&#x2F;Register Definition  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107232442328.png" alt="image-20241107232442328" style="zoom:50%;" />

<h4 id="2-3-3-代码分析"><a href="#2-3-3-代码分析" class="headerlink" title="2.3.3 代码分析"></a><font size=3>2.3.3 代码分析</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ldr r0, =0X020E0068	/* 将寄存器SW_MUX_GPIO1_IO03_BASE加载到r0中 */</span><br><span class="line">ldr r1, =0X5		/* 设置寄存器SW_MUX_GPIO1_IO03_BASE的MUX_MODE为5 */</span><br><span class="line">str r1,[r0]</span><br></pre></td></tr></table></figure>

<p>第 1~3 行：是设置GPIO1_IO03的复用功能， GPIO1_IO03的复用寄存器地址为0X020E0068，寄 存 器 IOMUXC_SW_MUX_CTL_PAD_GPIO1_IO03 的 MUX_MODE 设 置 为 5 就 是 将GPIO1_IO03 设置为 GPIO。 </p>
<h3 id="2-4-设置IO属性"><a href="#2-4-设置IO属性" class="headerlink" title="2.4 设置IO属性"></a><font size=3>2.4 设置IO属性</font></h3><h4 id="2-4-1-用哪个寄存器？"><a href="#2-4-1-用哪个寄存器？" class="headerlink" title="2.4.1 用哪个寄存器？"></a><font size=3>2.4.1 用哪个寄存器？</font></h4><p>设置IO属性的时候就是配置一下上下来、压摆率等相关参数，前面的复用功能配置集训期命名为SW_MUX_CTL_PAD_GPIO1_IO03，那么这里IO属性配置寄存器大概应该就是SW_PAD_CTL_PAD_GPIO1_IO03，我们直接全局搜索GPIO1_IO03，会在参考手册32.6.156 SW_PAD_CTL_PAD_GPIO1_IO03 SW PAD Control Register (IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO03)  中搜到这个寄存器：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233451803.png" alt="image-20241107233451803" style="zoom: 50%;" />

<p>这里面就是配置IO属性的地方，这里详细的可以直接去看手册。</p>
<h4 id="2-4-2-寄存器地址？"><a href="#2-4-2-寄存器地址？" class="headerlink" title="2.4.2 寄存器地址？"></a><font size=3>2.4.2 寄存器地址？</font></h4><p>还是那两个地方：</p>
<p>（1）32.6.156 SW_PAD_CTL_PAD_GPIO1_IO03 SW PAD Control Register (IOMUXC_SW_PAD_CTL_PAD_GPIO1_IO03) </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233612900.png" alt="image-20241107233612900" style="zoom:50%;" />

<p>（2）32.6 IOMUXC Memory Map&#x2F;Register Definition  </p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107233733355.png" alt="image-20241107233733355" style="zoom:50%;" />

<h4 id="2-4-3-代码分析"><a href="#2-4-3-代码分析" class="headerlink" title="2.4.3 代码分析"></a><font size=3>2.4.3 代码分析</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">/**</span><br><span class="line"> * bit 16:0 HYS关闭</span><br><span class="line"> * bit [15:14]: 00 默认下拉</span><br><span class="line">    * bit [13]: 0 kepper功能</span><br><span class="line">    * bit [12]: 1 pull/keeper使能</span><br><span class="line">    * bit [11]: 0 关闭开路输出</span><br><span class="line">    * bit [7:6]: 10 速度100Mhz</span><br><span class="line">    * bit [5:3]: 110 R0/6驱动能力</span><br><span class="line">    * bit [0]: 0 低转换率</span><br><span class="line">    */</span><br><span class="line">   ldr r0, =0X020E02F4	/*寄存器SW_PAD_GPIO1_IO03_BASE */</span><br><span class="line">   ldr r1, =0X10B0</span><br><span class="line">   str r1,[r0]</span><br></pre></td></tr></table></figure>

<p>第 11~13 行：是设置 GPIO1_IO03 的配置寄存器，也就是寄存器 IOMUX_SW_PAD_CTL_PAD_GPIO1_IO03 的值，此寄存器地址为 0X020E02F4，代码里面已经给出了这个寄存器详细的位设置。  </p>
<h3 id="2-5-设置GPIO功能"><a href="#2-5-设置GPIO功能" class="headerlink" title="2.5 设置GPIO功能"></a><font size=3>2.5 设置GPIO功能</font></h3><p>接下来就是配置GPIO为输出功能</p>
<h4 id="2-5-1-用哪个寄存器？"><a href="#2-5-1-用哪个寄存器？" class="headerlink" title="2.5.1 用哪个寄存器？"></a><font size=3>2.5.1 用哪个寄存器？</font></h4><p>这一次我们要用到GPIO外设模块的方向寄存器，我们找到参考手册的28.5.2 GPIO direction register (GPIOx_GDIR)  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234119303.png" alt="image-20241107234119303" style="zoom:50%;" />

<p>可以看到每一位控制一个GPIO引脚的方向，配置1为输出，0为输入，我们这里是GPIO1_IO03，所以这里就要配置GPIO[3]这一位为1。</p>
<h4 id="2-5-2-寄存器地址？"><a href="#2-5-2-寄存器地址？" class="headerlink" title="2.5.2 寄存器地址？"></a><font size=3>2.5.2 寄存器地址？</font></h4><p>那这个寄存器地址是什么？我们先看这里28.5.2 GPIO direction register (GPIOx_GDIR)  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234356064.png" alt="image-20241107234356064" style="zoom:50%;" />

<p>发现是Base + 4h，那么这个Base是什么？这个应该是GPIO外设的基地址，我们可以直接看28.5 GPIO Memory Map&#x2F;Register Definition  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234545683.png" alt="image-20241107234545683" style="zoom:50%;" />

<p>可以看到绝对地址是209_C004。那么基地址的话，应该是209_C000，我们来看一下存储器映像Chapter 2Memory Maps  这节的Table 2-2. AIPS-1 memory map (continued)  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234838793.png" alt="image-20241107234838793" style="zoom:50%;" />

<p>会发现GPIO1相关寄存器的基地址就是209_C000。</p>
<h4 id="2-5-3-代码分析"><a href="#2-5-3-代码分析" class="headerlink" title="2.5.3 代码分析"></a><font size=3>2.5.3 代码分析</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ldr r0, =0X0209C004	/*寄存器GPIO1_GDIR */</span><br><span class="line">   ldr r1, =0X0000008		</span><br><span class="line">   str r1,[r0]</span><br></pre></td></tr></table></figure>

<p>第 1~3 行：是设置 GPIO 功能，经过上面几步操作， GPIO1_IO03 这个 IO 已经被配置为了GPIO 功能，所以还需要设置跟 GPIO 有关的寄存器。这几行是设置 GPIO1&rarr;GDIR 寄存器，将 GPIO1_IO03 设置为输出模式，也就是寄存器的 GPIO1_GDIR 的 bit3 置 1。  </p>
<h3 id="2-6-设置GPIO输出电平"><a href="#2-6-设置GPIO输出电平" class="headerlink" title="2.6 设置GPIO输出电平"></a><font size=3>2.6 设置GPIO输出电平</font></h3><h4 id="2-6-1-用哪个寄存器？"><a href="#2-6-1-用哪个寄存器？" class="headerlink" title="2.6.1 用哪个寄存器？"></a><font size=3>2.6.1 用哪个寄存器？</font></h4><p>前面说过了，这里要用数据寄存器28.5.1 GPIO data register (GPIOx_DR)  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107235412338.png" alt="image-20241107235412338" style="zoom:50%;" />

<p>这里还是没一位控制一个引脚。</p>
<h4 id="2-6-2-寄存器地址？"><a href="#2-6-2-寄存器地址？" class="headerlink" title="2.6.2 寄存器地址？"></a><font size=3>2.6.2 寄存器地址？</font></h4><p>和方向寄存器一样，我们直接看28.5 GPIO Memory Map&#x2F;Register Definition  ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241107234545683.png" alt="image-20241107234545683" style="zoom:50%;" />

<h4 id="2-6-3-代码分析"><a href="#2-6-3-代码分析" class="headerlink" title="2.6.3 代码分析"></a><font size=3>2.6.3 代码分析</font></h4><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ldr r0, =0X0209C000	/*寄存器GPIO1_DR */</span><br><span class="line">ldr r1, =0		</span><br><span class="line">str r1,[r0]</span><br></pre></td></tr></table></figure>

<p>第 1~3 行设置 GPIO1&rarr;DR 寄存器，也就是设置 GPIO1_IO03 的输出，我们要点亮开发板上的 LED0，那么 GPIO1_IO03 就必须输出低电平，所以这里设置 GPIO1_DR 寄存器为 0。  </p>
<h3 id="2-7-死循环"><a href="#2-7-死循环" class="headerlink" title="2.7 死循环"></a><font size=3>2.7 死循环</font></h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">loop:</span><br><span class="line">	b loop 	</span><br></pre></td></tr></table></figure>

<p>通过 b 指令， CPU 重复不断的跳到 loop 函数执行，进入一个死循环。  防止程序不受控制，跑到位置的地方。</p>
<h1 id="四、编译程序"><a href="#四、编译程序" class="headerlink" title="四、编译程序"></a><font size=3>四、编译程序</font></h1><h2 id="1-arm-linux-gnueabihf-gcc-编译文件"><a href="#1-arm-linux-gnueabihf-gcc-编译文件" class="headerlink" title="1. arm-linux-gnueabihf-gcc 编译文件  "></a><font size=3>1. arm-linux-gnueabihf-gcc 编译文件  </font></h2><p>我们是要编译出在 ARM 开发板上运行的可执行文件，所以要使用我们安装的交叉编译器 arm-linux-gnueabihf-gcc 来编译。先将 led.s 编译为对应的.o 文件，在终端中输入如下命令：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arm-linux-gnueabihf-gcc -g -c led.s -o led.o</span><br></pre></td></tr></table></figure>

<p>上述命令就是将 led.s 编译为 led.o，其中“-g”选项是产生调试信息， GDB 能够使用这些调试信息进行代码调试。“-c”选项是编译源文件，但是不链接。“-o”选项是指定编译产生的文件名字，这里我们指定 led.s 编译完成以后的文件名字为 led.o。执行上述命令以后就会编译生成一个 led.o 文件，如下图所示：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000415390.png" alt="image-20241108000415390" />

<p>led.o 文件并不是我们可以下载到开发板中运行的文件，一个工程中所有的 C 文件和汇编文件都会编译生成一个对应的.o 文件，我们需要将这.o 文件链接起来组合成可执行文件。</p>
<h2 id="2-arm-linux-gnueabihf-ld-链接文件"><a href="#2-arm-linux-gnueabihf-ld-链接文件" class="headerlink" title="2. arm-linux-gnueabihf-ld 链接文件  "></a><font size=3>2. arm-linux-gnueabihf-ld 链接文件  </font></h2><p>arm-linux-gnueabihf-ld 用来将众多的.o 文件链接到一个指定的链接位置。我们在学习SMT32 的时候基本就没有听过“链接”这个词，我们一般用 MDK 编写好代码，然后点击“编译”， MDK 或者 IAR 就会自动帮我们编译好整个工程，最后再点击“下载”就可以将代码下载到开发板中。 详细的内容这里就不再说了，之前学习STM32的时候详细的分析过。</p>
<p>我们要区分“存储地址”和“运行地址”这两个概念，“存储地址”就是可执行文件存储在哪里，可执行文件的存储地址可以随意选择。“运行地址”就是代码运行的时候所处的地址，这个我们在链接的时候就已经确定好了，代码要运行，那就必须处于运行地址处，否则代码肯定运行出错。比如 I.MX6U 支持 SD 卡、 EMMC、 NAND 启动，因此代码可以存储到 SD 卡、 EMMC 或者 NAND 中，但是要运行的话就必须将代码从 SD 卡、 EMMC 或者NAND 中拷贝到其运行地址(链接地址)处，“存储地址”和“运行地址”可以一样，比如STM32 的存储起始地址和运行起始地址都是 0X08000000。</p>
<p>因此我们现在需要做的就是确定一下点灯的汇编程序最终的可执行文件其运行起始地址，也就是链接地址。上电以后 I.MX6U 的内部 boot rom 程序会将可执行文件拷贝到链接地址处，这个链接地址可以在 I.MX6U 的内部 128KB RAM 中(0X900000~0X91FFFF)，也可以在外部的 DDR 中，DDR中链接起始地址为 0X87800000。我们可以看一下I.MX6ULL的存储器映像</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20230716190816114.png" alt="image-20230716190816114" style="zoom:50%;" />

<p>I.MX6U-ALPHA 开发板的 DDR 容量有两种： 512MB 和256MB，起始地址都为 0X80000000，只不过 512MB 的终止地址为 0X9FFFFFFF，而256MB 容量的终止地址为 0X8FFFFFFF。之所以选择 0X87800000 这个地址是因为后面要学习的 u-boot 其链接地址就是 0X87800000，这样我们统一使用 0X87800000 这个链接地址，不容易记混。    </p>
<p>确定了链接地址以后就可以使用 arm-linux-gnueabihf-ld 来将前面编译出来的 led.o 文件链接到 0X87800000 这个地址，使用如下命令：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arm-linux-gnueabihf-ld -Ttext 0X87800000 led.o -o led.elf</span><br></pre></td></tr></table></figure>

<p>“ -Ttext ”就是指定链接地址，“-o”选项指定链接生成的 elf 文件名，这里我们命名为 led.elf。上述命令执行完以后就会在工程目录下多一个 led.elf 文件 ：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000446239.png" alt="image-20241108000446239" />

<p>led.elf 文件也不是我们最终烧写到 SD 卡中的可执行文件，我们要烧写镜像是使用的.bin 文件，因此还需要将 led.elf 文件转换为.bin 文件，这里我们就需要用到 arm-linux-gnueabihf-objcopy 这个工具了。  </p>
<h2 id="3-arm-linux-gnueabihf-objcopy-格式转换"><a href="#3-arm-linux-gnueabihf-objcopy-格式转换" class="headerlink" title="3. arm-linux-gnueabihf-objcopy 格式转换  "></a><font size=3>3. arm-linux-gnueabihf-objcopy 格式转换  </font></h2><p>arm-linux-gnueabihf-objcopy 更像一个格式转换工具，我们需要用它将 led.elf 文件转换为led.bin 文件，命令如下：</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin</span><br></pre></td></tr></table></figure>

<p>“-O”选项指定以什么格式输出，后面的“binary”表示以二进制格式输出，选项“-S”表示不要复制源文件中的重定位信息和符号信息，“-g”表示不复制源文件中的调试信息。上述命令执行完成以后，就会生成一个bin文件：</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000520398.png" alt="image-20241108000520398" />

<p>这个.bin文件也不能直接放到开发板上运行， 这次是因为需要在.bin文件缺少启动相关信息。</p>
<h2 id="4-arm-linux-gnueabihf-objdump-反汇编"><a href="#4-arm-linux-gnueabihf-objdump-反汇编" class="headerlink" title="4. arm-linux-gnueabihf-objdump 反汇编  "></a><font size=3>4. arm-linux-gnueabihf-objdump 反汇编  </font></h2><p>大多数情况下我们都是用 C 语言写程序的，有时候需要查看其汇编代码来调试代码，因此就需要进行反汇编，一般可以将 elf 文件反汇编，比如如下命令：  </p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">arm-linux-gnueabihf-objdump -D led.elf &gt; led.dis</span><br></pre></td></tr></table></figure>

<p>“-D”选项表示反汇编所有的段，反汇编完成以后就会在当前目录下出现一个名为 led.dis 文件:</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000549113.png" alt="image-20241108000549113" />

<p>可以打开 led.dis 文件看一下，看看是不是汇编代码 :</p>
<img data-src="https://fanhua-picture.oss-cn-hangzhou.aliyuncs.com/01%E5%B5%8C%E5%85%A5%E5%BC%8F%E5%BC%80%E5%8F%91/02IMX6ULL%E5%B9%B3%E5%8F%B0/LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/LV04-02-GPIO-02-%E6%B1%87%E7%BC%96%E7%82%B9%E4%BA%AELED%E7%81%AF/img/image-20241108000654980.png" alt="image-20241108000654980" />

<p>可以看出 led.dis 里面是汇编代码，而且还可以看到内存分配情况。在0X87800000 处就是全局标号_start，也就是程序开始的地方。通过 led.dis 这个反汇编文件可以明显的看出我们的代码已经链接到了以 0X87800000 为起始地址的区域。  </p>
<h2 id="5-创建-Makefile-文件"><a href="#5-创建-Makefile-文件" class="headerlink" title="5. 创建 Makefile 文件  "></a><font size=3>5. 创建 Makefile 文件  </font></h2><p>前边那样一条一条太麻烦了，之前都学过makefile了，那刚好可以用啦。用“touch”命令在工程根目录下创建一个名为“Makefile”的文件，并添加以下内容：</p>
<figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="section">led.bin:led.s</span></span><br><span class="line">	arm-linux-gnueabihf-gcc -g -c led.s -o led.o</span><br><span class="line">	arm-linux-gnueabihf-ld -Ttext 0X87800000 led.o -o led.elf</span><br><span class="line">	arm-linux-gnueabihf-objcopy -O binary -S -g led.elf led.bin</span><br><span class="line">	arm-linux-gnueabihf-objdump -D led.elf &gt; led.dis</span><br><span class="line">	</span><br><span class="line"><span class="meta"><span class="keyword">.PHONY</span>: clean</span></span><br><span class="line"><span class="section">clean:</span></span><br><span class="line">	rm -rf *.o led.bin led.elf led.dis</span><br></pre></td></tr></table></figure>

<p>之后我们直接一个make就可以完成编译啦。</p>
<h1 id="五、程序烧写"><a href="#五、程序烧写" class="headerlink" title="五、程序烧写"></a><font size=3>五、程序烧写</font></h1><p>后边一小节再说。</p>

    </div>

    
    
    

    <footer class="post-footer">




    <div>
        
            <div style="text-align:center;color: #ccc;font-size:14px;">
            ----------本文结束
            <i class="fas fa-fan fa-spin" style="color: #FF1493; font-size: 1rem"></i>
            感谢您的阅读----------
            </div>
        
    </div>





  
  <div class="my_post_copyright"> 
    <p><span>文章标题:</span><a href="/post/35c09a55.html">LV04-02-GPIO-02-汇编点亮LED灯</a></p>
    <p><span>文章作者:</span><a href="/" title="欢迎访问 《苏木》 的学习笔记">苏木</a></p>
    <p><span>发布时间:</span>2024年11月08日 - 20:59</p>
    <p><span>最后更新:</span>2025年06月14日 - 00:25</p>
    <p><span>原始链接:</span><a href="/post/35c09a55.html" title="LV04-02-GPIO-02-汇编点亮LED灯">https://sumumm.github.io/post/35c09a55.html</a></p>
    <p><span>许可协议:</span><i class="fab fa-creative-commons"></i> <a rel="license" href= "https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank" title="Attribution-NonCommercial-NoDerivatives 4.0 International (CC BY-NC-ND 4.0)">署名-非商业性使用-禁止演绎 4.0 国际</a> 转载请保留原文链接及作者。</p>  
  </div>
  


          <div class="post-tags">
              <a href="/tags/ALPHA-LV04-%E8%A3%B8%E6%9C%BA%E5%BC%80%E5%8F%91/" rel="tag"><i class="fa fa-tag"></i> (ALPHA)LV04-裸机开发</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/post/8cf1af4a.html" rel="prev" title="LV04-02-GPIO-03-裸机程序烧写">
                  <i class="fa fa-angle-left"></i> LV04-02-GPIO-03-裸机程序烧写
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/post/2a85f40a.html" rel="next" title="LV04-02-GPIO-01-GPIO简介">
                  LV04-02-GPIO-01-GPIO简介 <i class="fa fa-angle-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">

  <div class="copyright">
    &copy; 2017 – 
    <span itemprop="copyrightYear">2025</span>
    <span class="with-love">
      <i class="fa fa-heart"></i>
    </span>
    <span class="author" itemprop="copyrightHolder">苏木</span>
  </div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
      <span>站点总字数：</span>
    <span title="站点总字数">3.7m</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
      <span>站点阅读时长 &asymp;</span>
    <span title="站点阅读时长">225:26</span>
  </span>
</div>




    <span id="sitetime"></span>
    <script defer language=javascript>
        function siteTime()
        {
            window.setTimeout("siteTime()", 1000);
            var seconds = 1000;
            var minutes = seconds * 60;
            var hours = minutes * 60;
            var days = hours * 24;
            var years = days * 365;
            var today = new Date();
            var todayYear = today.getFullYear();
            var todayMonth = today.getMonth()+1;
            var todayDate = today.getDate();
            var todayHour = today.getHours();
            var todayMinute = today.getMinutes();
            var todaySecond = today.getSeconds();
            /*==================================================
            Date.UTC() -- 返回date对象距世界标准时间(UTC)1970年1月1日午夜之间的毫秒数(时间戳)
            year        - 作为date对象的年份，为4位年份值
            month       - 0-11之间的整数，做为date对象的月份
            day         - 1-31之间的整数，做为date对象的天数
            hours       - 0(午夜24点)-23之间的整数，做为date对象的小时数
            minutes     - 0-59之间的整数，做为date对象的分钟数
            seconds     - 0-59之间的整数，做为date对象的秒数
            microseconds - 0-999之间的整数，做为date对象的毫秒数
            ==================================================*/
            var t1 = Date.UTC(2017, 
                              5, 
                              19, 
                              0, 
                              0, 
                              0); //北京时间
            var t2 = Date.UTC(todayYear,todayMonth,todayDate,todayHour,todayMinute,todaySecond);
            var diff = t2-t1;
            var diffYears = Math.floor(diff/years);
            var diffDays = Math.floor((diff/days)-diffYears*365);
            var diffHours = Math.floor((diff-(diffYears*365+diffDays)*days)/hours);
            var diffMinutes = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours)/minutes);
            var diffSeconds = Math.floor((diff-(diffYears*365+diffDays)*days-diffHours*hours-diffMinutes*minutes)/seconds);
            document.getElementById("sitetime").innerHTML="已在这里 "+diffYears+" 年 "+diffDays+" 天 "+diffHours+" 小时 "+diffMinutes+" 分钟 "+diffSeconds+" 秒";
        }
        siteTime();
    </script>



    </div>
  </footer>

  
  <div class="back-to-top" role="button" aria-label="返回顶部">
    <i class="fa fa-arrow-up fa-lg"></i>
    <span>0%</span>
  </div>
  <div class="reading-progress-bar"></div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/next-theme-pjax/0.6.0/pjax.min.js" integrity="sha256-vxLn1tSKWD4dqbMRyv940UYw4sXgMtYcK6reefzZrao=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/fancyapps-ui/5.0.28/fancybox/fancybox.umd.js" integrity="sha256-ytMJGN3toR+a84u7g7NuHm91VIR06Q41kMWDr2pq7Zo=" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js" integrity="sha256-mOFREFhqmHeQbXpK2lp4nA3qooVgACfh88fpJftLBbc=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script><script src="/js/pjax.js"></script>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/hexo-generator-searchdb/1.4.1/search.js" integrity="sha256-1kfA5uHPf65M5cphT2dvymhkuyHPQp5A53EGZOnOLmc=" crossorigin="anonymous"></script>
<script src="/js/third-party/search/local-search.js"></script>




  <script src="/js/third-party/fancybox.js"></script>

  <script src="/js/third-party/pace.js"></script>


  




  

  <script class="next-config" data-name="enableMath" type="application/json">true</script><script class="next-config" data-name="mathjax" type="application/json">{"enable":true,"tags":"none","js":{"url":"https://cdnjs.cloudflare.com/ajax/libs/mathjax/3.2.2/es5/tex-mml-chtml.js","integrity":"sha256-MASABpB4tYktI2Oitl4t+78w/lyA+D7b/s9GEP0JOGI="}}</script>
<script src="/js/third-party/math/mathjax.js"></script>


 
        <div id="click-show-text"
            data-mobile = false
            data-text = 富强,民主,文明,和谐,自由,平等,公正,法制,爱国,敬业,诚信,友善
            data-fontsize = 15px
            data-random= false>
        </div>
       

      
        <script async src=https://cdn.jsdelivr.net/npm/hexo-next-mouse-effect@latest/click/showText.js></script>
      

      
    




    <script async src="/js/fancybox_param.js"></script>





<!-- APlayer本体 -->



</body>
</html>
